<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  
  <div id="app"></div>
  
  <script src="../react-js/react.development.js" crossorigin></script>
  <script src="../react-js/react-dom.development.js" crossorigin></script>
  <script src="../react-js/babel.min.js"></script>

  <script type="text/babel">
    class App extends React.Component {
      constructor() {
        super()

        this.state = {
          //1. 在{} 可以正常显示的内容
          message: 'Hello React ！',
          age: 18,
          array: ['111', '222', '333'],

          //2.在 {} 中是不显示 可以转成字符串
          test: null,
          test2: undefined,
          test3: true,
          test4: false,

          // object: {
          //   sum: 0,
          //   demo: '多少啊'
          // }

          flag: true,
          firstName: '嘻嘻嘻',
          lastName: '哈哈哈'
        }
      }

      render() {
        { /* 结构state */ }
        const { flag } = this.state
        
        return (
          <div>
            <h2>{ this.state.message }</h2>
            <h2>{ this.state.age }</h2>
            <h2>{ this.state.array }</h2>
            <h2>{ this.state.object }</h2> {  /* 对象类型不能作为子元素 */}

            <hr />
            <h2>{ this.state.test  + '' }</h2>      { /* 2.1*/ }
            <h2>{ String(this.state.test2) }</h2>   { /* 2.2*/ }
            <h2>{ this.state.test3.toString() }</h2> { /* 2.3布尔值默认有toString方法 调用转字符串就能显示 */ }
            <h2>{ this.state.test4.toString() }</h2>

            <hr />{ /*3. 嵌入js表达式 */ }
            <h2>{ flag ? 'noMore' : 'more' }</h2>
            <h2>{ this.getAllName() }</h2>
          </div>
        )
      }

      getAllName() {
        const { firstName, lastName } = this.state
        return firstName + '~~~' + lastName
      }

    }

    ReactDOM.render(<App/>, document.getElementById('app'))
  </script>
  
</body>
</html>